import 'package:flutter/material.dart';

/*
 * @author[hansen]
 * @version[创建日期，2022/5/25 17:53]
 * @function[通用dialog ]
 */
class MaterialDialog extends StatelessWidget {
  final String? title;
  final String? content;
  final String? cancelText;
  final String? confirmText;
  final TextStyle? titleTextStyle;
  final TextStyle? contentTextStyle;
  final TextStyle? cancelTextStyle;
  final TextStyle? confirmTextStyle;
  final bool? showConfirm;

  final Function()? onCancel;
  final Function()? onConfirm;

  const MaterialDialog({
    Key? key,
    this.title,
    this.content,
    this.cancelText,
    this.confirmText,
    this.titleTextStyle,
    this.contentTextStyle,
    this.cancelTextStyle,
    this.confirmTextStyle,
    this.onCancel,
    this.onConfirm,
    this.showConfirm,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Dialog(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.fromLTRB(0, 20, 0, 20),
            child: Text(
              title ?? "标题",
              style: titleTextStyle ??
                  const TextStyle(
                    color: Color(0xFF303133),
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.fromLTRB(20, 0, 20, 15),
            child: Text(
              content ?? "内容",
              textAlign: TextAlign.center,
              style: contentTextStyle ??
                  const TextStyle(
                    color: Color(0xFF909399),
                    fontSize: 14,
                  ),
            ),
          ),
          const Divider(
            height: 10,
            color: Colors.transparent,
          ),
          Container(
            height: 1,
            color: const Color(0x103C3C43),
          ),
          Row(
            children: [
              Expanded(
                child: GestureDetector(
                  child: Padding(
                    padding: const EdgeInsets.fromLTRB(0, 15, 0, 15),
                    child: Text(
                      cancelText ?? "取消",
                      textAlign: TextAlign.center,
                      style: cancelTextStyle ??
                          const TextStyle(
                            color: Color(0xFF909399),
                            fontSize: 15,
                            fontWeight: FontWeight.bold,
                          ),
                    ),
                  ),
                  onTap: onCancel ?? () {
                    Navigator.of(context).pop();
                  },
                ),
              ),
              Visibility(
                visible: showConfirm ?? true,
                child: Expanded(
                  child: GestureDetector(
                    child: Container(
                      padding: const EdgeInsets.fromLTRB(0, 15, 0, 15),
                      decoration: const BoxDecoration(
                        border: Border(
                          left: BorderSide(
                            color: Color(0x103C3C43),
                            width: 1,
                          ),
                        ),
                      ),
                      child: Text(
                        confirmText ?? "确定",
                        textAlign: TextAlign.center,
                        style: confirmTextStyle ??
                            const TextStyle(
                              color: Color(0xFFC20014),
                              fontSize: 15,
                              fontWeight: FontWeight.bold,
                            ),
                      ),
                    ),
                    onTap: onConfirm,
                  ),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }
}
